package com.zzyk.main.model.vo;

import java.util.Calendar;
import java.util.Date;

public class TimePair {
    private Date startTime;
    private Date endTime;

    private TimePair(Date startTime, Date endTime) {
        this.startTime = startTime;
        this.endTime = endTime;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public static TimePair checkTime(Date startTime, Date endTime) {
        if (startTime == null && endTime == null) {
            endTime = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(endTime);
            calendar.roll(Calendar.DAY_OF_MONTH, -1);
            if (calendar.getTime().after(endTime)) {
                calendar.roll(Calendar.MONTH, -1);
            }
            if (calendar.getTime().after(endTime)) {
                calendar.roll(Calendar.YEAR, -1);
            }
            startTime = calendar.getTime();
        } else if (startTime == null) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(endTime);
            calendar.roll(Calendar.DAY_OF_MONTH, -7);
            if (calendar.getTime().after(endTime)) {
                calendar.roll(Calendar.MONTH, -1);
            }
            if (calendar.getTime().after(endTime)) {
                calendar.roll(Calendar.YEAR, -1);
            }
            startTime = calendar.getTime();
        } else if (endTime == null) {
            endTime = new Date();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(endTime);
        calendar.roll(Calendar.DAY_OF_MONTH, 1);
        if (calendar.getTime().before(startTime)) {
            calendar.roll(Calendar.MONTH, 1);
        }
        endTime = calendar.getTime();
        return new TimePair(startTime, endTime);
    }
}